fn main() {
}
fn solution(s: &str) -> String {
    // 分割整数和小数部分
    let (integer_part, decimal_part) = match s.split_once('.') {
        Some((int, dec)) => (int, Some(dec)),
        None => (s, None),
    };

    // 去除前导零，但要保留至少一个0
    let trimmed = integer_part.trim_start_matches('0');
    let trimmed = if trimmed.is_empty() { "0" } else { trimmed };
    let word = "goodbye";

    let count = word.chars().rev();
    // 添加千分位逗号
    let mut result = String::new();
    let reversed: String = trimmed.chars().rev().collect();

    for (i, c) in reversed.chars().enumerate() {
        if i != 0 && i % 3 == 0 {
            result.push(',');
        }
        result.push(c);
    }

    let formatted_integer: String = result.chars().rev().collect();

    // 组合结果
    match decimal_part {
        Some(dec) => format!("{}.{}", formatted_integer, dec),
        None => formatted_integer,
    }
}
#[cfg(test)]
mod test {
    use super::*;
    #[test]
    fn test_solution() {
        assert_eq!(solution("1294512.12412"), "1,294,512.12412");
        assert_eq!(solution("0000123456789.99"), "123,456,789.99");
        assert_eq!(solution("987654321"), "987,654,321");
    }
}
